package top;

import utils.Common;

import java.util.Properties;

public class ConfigCenter {
/*
    // DAO //////////////////////////////////////////////////////////////////////////////////////////////////

    private static final UsersManagement  userManager    = new UsersManager();
    private static final StoresManagement storesManager  = new StoresManager();

    // SERVICE //////////////////////////////////////////////////////////////////////////////////////////////

    private static final AccountService   accountService = new AccountServiceImp(userManager);
    private static final StoreService     storeService   = new StoreServiceImp  (storesManager, accountService);
    //-------------------------------------------------------------------------------------------------------
    public static final AccountService getAccountService() { return accountService; }
    public static final StoreService   getStoreService()   { return storeService; }
*/
    // LOCAL-FILESYSTEM /////////////////////////////////////////////////////////////////////////////////////

    public static final String CONFIGHOME           = Common.initDirectory("./etc/z5col");
    public static final String DATAHOME             = "/data/z5col"; // at web app root dir/data

    public static final String FILEHOME             = DATAHOME + "/z5col_files";
    public static final String PICHOME              = FILEHOME + "/pictures";

    public static final String DBCONFIGFILE         = CONFIGHOME + "/z5col_database.cfg";
    public static final String FILEUPLOADCONFIGFILE = CONFIGHOME + "/z5col_fileUpload.cfg";
    public static final String ACCOUNTCONFIGFILE    = CONFIGHOME + "/z5col_logAccount.cfg";

    // CONFIG-PROPERTIES ////////////////////////////////////////////////////////////////////////////////////

    public static Properties getFileUploadConfig()            { return fileUploadConfig; }
    public static String     getFileUploadConfig(String prop) { return fileUploadConfig.getProperty(prop); }
    public static Properties getDatabaseConfig()              { return databaseConfig; }
    public static String     getDatabaseConfig(String prop)   { return databaseConfig.getProperty(prop); }
    public static Properties getAccountConfig()               { return accountConfig; }
    public static String     getAccountConfig(String prop)    { return accountConfig.getProperty(prop); }

    // INIT-FILEUPLOAING-CONFIG /////////////////////////////////////////////////////////////////////////////

    private static Properties fileUploadConfig = initFileUploadConfig();

    private static Properties initFileUploadConfig() {
        Properties defaultCfg = new Properties();
        defaultCfg.put("DEFAULT_MEMORY_THRESHOLD", "4194304");  // 4MB
        defaultCfg.put("DEFAULT_MAX_FILE_SIZE",    "33554432"); //32MB
        defaultCfg.put("DEFAULT_MAX_REQUEST_SIZE", "67108864"); //64MB
        return Common.initConfig(defaultCfg, FILEUPLOADCONFIGFILE);
    }

    // INIT-DATASOURCE //////////////////////////////////////////////////////////////////////////////////////

    private static Properties databaseConfig = initDatabaseConfig();

    private static Properties initDatabaseConfig() {
        Properties defaultCfg = new Properties();
        defaultCfg.put("dbname", "z5col");
        defaultCfg.put("port", "3306");
        defaultCfg.put("ip", "1.116.124.70");
        defaultCfg.put("dbuser", "z5cPlayer");
        defaultCfg.put("dbpasswd", "dftz5cplayer");
        defaultCfg.put("connectionUsingTimeOut", "16");
        defaultCfg.put("connectionIdleTimeOut", "32");
        defaultCfg.put("minConnectionCount", "4");
        defaultCfg.put("maxConnectionCount", "64");
        defaultCfg.put("heartBeatTime", "32");
        return Common.initConfig(defaultCfg, DBCONFIGFILE);
    }

    // INIT-ACCOUNT-CONFIG //////////////////////////////////////////////////////////////////////////////////

    private static Properties accountConfig = initAccountConfig();

    private static Properties initAccountConfig() {
        Properties defaultCfg = new Properties();
        defaultCfg.put("autoLogingLifeTime", "2592000"); //30Days
        return Common.initConfig(defaultCfg, ACCOUNTCONFIGFILE);
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////
}
